package com.tensquare.friend.controller;

import com.tensquare.friend.service.FriendService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:zimmor
 * @Date: 2021/3/16 11:53
 * @Description 控制层
 * @version: 1.0.0
 */
@RestController
@CrossOrigin
@RequestMapping("/friend")
public class FriendController {
    @Autowired
    private FriendService friendService;

    /**
     * 添加好友
     * @param friendid
     * @param type
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT, value = "/like/{friendid}/{type}")
    public Result addFriend(@PathVariable String friendid, @PathVariable String type) {
        String userid = "2";
        friendService.addFriend(userid, friendid, type);
        return new Result(true, StatusCode.OK, "操作成功");
    }

    /**
     * 删除好友
     * @param friendid
     * @return
     */
    @RequestMapping(method = RequestMethod.DELETE, value = "/{friendid}")
    public Result deleteFriend(@PathVariable String friendid) {
        String userid = "2";
        //删除好友
        friendService.deleteFriendById(userid, friendid);
        return new Result(true, StatusCode.OK, "删除好友成功");
    }
}
